//define(["jquery","utils","HeatPoint"], function($, utils,HeatPoint){
define(["jquery","utils","heatmap","KeyVisualizer","HeatMapAreaAdminInterfaceList"], function($, utils,h337,KeyVisualizer,HeatMapAreaAdminInterfaceList){
    
    function HeatMapAdminInterface(xDataManager) {

		this.visualizerKeyPressed 		= null;
		this.visualizerCharAnalysis		= null;
		this.dataManager				= xDataManager;
		this.divBtnWrapper 				= null;
		this.divMainInterface 			= null;
		this.adminInterfaceULClick 		= null;
		this.adminInterfaceULMove 		= null;
		this.adminInterfaceULPressed	= null;
		this.adminInterfaceULChar 		= null;



	};
    $.extend(HeatMapAdminInterface.prototype, {

    	init : function(){
			
			var t = this;
			t.visualizerKeyPressed = new KeyVisualizer();
			t.visualizerCharAnalysis = new KeyVisualizer();
			t.visualizerKeyPressed.init();
			t.visualizerCharAnalysis.init();
			t.initMainInterface();
			t.initAdminButtons();

			t.visualizerKeyPressed.toggle();
			t.visualizerCharAnalysis.toggle();
    	},
		initMainInterface: function (){
			var t = this;
			t.divMainInterface = document.createElement("DIV");
			$(t.divMainInterface).addClass("coreControl");
		 	$(document.body).prepend(t.divMainInterface);
		},
    	initAdminButtons:function(){
    		this.initBtnWrapper();
    		this.initVisualizerButton(this.visualizerKeyPressed,"KeyPressed");
    		this.initVisualizerButton(this.visualizerCharAnalysis,"CharAnalysis");
    	},
    	warrapIt: function(toWrap){
			var wrapper= $(document.createElement("div"));
			$(wrapper).addClass("coreControlWrapper");
			$(wrapper).append(toWrap);
			$(this.divMainInterface).append(wrapper);
    	},
		initAreaListInterfaceMouseClick: function(heatAreaList){
			
			this.adminInterfaceULClick = new HeatMapAreaAdminInterfaceList(heatAreaList);
			this.adminInterfaceULClick.init();
			this.warrapIt(this.adminInterfaceULClick.domUL);

		},
		initAreaListInterfaceMouseMove: function(heatAreaList){
			
			this.adminInterfaceULMove = new HeatMapAreaAdminInterfaceList(heatAreaList);
			this.adminInterfaceULMove.init();
			this.warrapIt(this.adminInterfaceULMove.domUL);
			
		},
		initAreaListInterfaceKeyPressed: function(heatAreaList){
			
			this.adminInterfaceULPressed = new HeatMapAreaAdminInterfaceList(heatAreaList);
			this.adminInterfaceULPressed.init();
			this.warrapIt(this.adminInterfaceULPressed.domUL);
		},
    	initAreaListInterfaceCharAnalysis: function(heatAreaList){
			
			this.adminInterfaceULChar = new HeatMapAreaAdminInterfaceList(heatAreaList);
			this.adminInterfaceULChar.init();
			this.warrapIt(this.adminInterfaceULChar.domUL);
    	},
    	initBtnWrapper:function(){
    		
    		if (this.divBtnWrapper != null) return true;
			
			this.divBtnWrapper = document.createElement("DIV");
			

			$(this.divBtnWrapper).addClass("coreControlWrapper");
			$(this.divMainInterface).append(this.divBtnWrapper);

			if(this.divBtnWrapper != null) return true;
    	},
    	initHeatmapTypeLists:function(){

    	},
    	initLoadDataButton: function(delegateHandler){
    		var t = this;
    		// var pBtn = document.createElement('BUTTON');
			var fileInput = document.createElement("INPUT");
			fileInput.id = "fileSelectorHeatData";
			fileInput.setAttribute("type", "file");
			fileInput.setAttribute("name", "files[]");
			fileInput.addEventListener('change', delegateHandler, false);
			$(this.divBtnWrapper).prepend(fileInput);
    	},
    	initVisualizerButton:function(visualizer,caption){
    		var t = this;
	        var pBtn = document.createElement('BUTTON');
	        
			$(pBtn).text(caption);
			$(pBtn).addClass('coreControlButton');
	        pBtn.onclick = function(){
	        	visualizer.toggle();
	        	t.visualizerKeyPressed.positionHeatmap();
	        	t.visualizerCharAnalysis.positionHeatmap();
	        }; 	
        
			$(t.divBtnWrapper).append(pBtn);
    	}, 
    	getCharAnylysisHeatmap: function(){
			if (this.visualizerCharAnalysis == null|| this.visualizerCharAnalysis.getHeatmap() == null) return null;
			return this.visualizerCharAnalysis.getHeatmap();
    	},
    	getKeyPressedHeatmap: function(){
    		if (this.visualizerKeyPressed == null || this.visualizerKeyPressed.getHeatmap() == null) return null;
    		return this.visualizerKeyPressed.getHeatmap();
    	},
    	clearVisualizer: function(){
    		this.visualizerCharAnalysis.getHeatmap().clear();
			this.visualizerKeyPressed.getHeatmap().clear();
    	}
    });

   return HeatMapAdminInterface;
});
